package algotithm.acwing.test799;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/6-14:49
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String[] nums = reader.readLine().split(" ");
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(nums[i]);
        }
        System.out.println(maxLength(arr));
    }

    public static int maxLength(int[] arr) {
        int res = 0;
        HashMap<Integer,Integer> map = new HashMap<>();
        for (int i = 0, j = 0; i < arr.length; i++) {
            map.put(arr[i],map.getOrDefault(arr[i],0) + 1);
            while (map.get(arr[i]) > 1) {
                map.put(arr[j],map.get(arr[j])-1);
                j++;
            }
            res = Math.max(res,i-j+1);
        }
        return res;
    }


}
